package com.yzt.zhuju.dialog;

import android.app.Dialog;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.yzt.zhuju.R;
import com.yzt.p_base.utils.DisplayUtils;

/**
 * author : bob
 * date   : 2022/12/1
 * desc   : 解绑弹窗
 */
public class AccountUnBindDialog extends CenterBaseDialog {

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_fragment_bind;
    }

    @Override
    public void bindView(View v) {
        TextView mSubmitTv = v.findViewById(R.id.submit_tv);
        mSubmitTv.setOnClickListener(this);
        v.findViewById(R.id.cancel_tv).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v.getId() == R.id.cancel_tv) {
            dismiss();
            listener.cancel();
        } else if (v.getId() == R.id.submit_tv) {
            dismiss();
            listener.submit();
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        Window window = dialog.getWindow();
        if (window != null) {
            WindowManager.LayoutParams windowParams = window.getAttributes();
            windowParams.dimAmount = 0.5f;
            window.setAttributes(windowParams);

            WindowManager.LayoutParams params = window.getAttributes();
            params.gravity = getGravity();
            params.width = DisplayUtils.getDisplayPxWidth() - DisplayUtils.dp2px(80);
            params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
            window.setAttributes(params);
        }
        dialog.setCanceledOnTouchOutside(true);
    }

    private OnSelectDialogListener listener;

    public void setOnSelectDialogListener(OnSelectDialogListener listener) {
        this.listener = listener;
    }

    public interface OnSelectDialogListener {

        void cancel();

        void submit();
    }
}
